﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntLibEC.Biz.Basic;
using EntLibEC.Info.Basic;
using EntLibEC.Cmn;

namespace EntLibEC.View.Cmn
{
    public partial class NewCategory12 : System.Web.UI.UserControl
    {
        private CustomizedCategoryManager cm = CustomizedCategoryManager.GetInstance();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void BindCategory()
        {
            BindC1();
            BindC2();
        }
        private void BindC1()
        {
            ddlC1.Items.Clear();
            List<CustomizedCategoryInfo> sl = cm.GetCategoryList(1);
            if (sl != null && sl.Count != 0)
            {
                foreach (CustomizedCategoryInfo item in sl)
                {
                    ddlC1.Items.Add(
                        new ListItem(item.ToString(), item.SysNo.ToString()));
                }
            }
            ddlC1.Items.Insert(0, new ListItem(AppConst.AllSelectString, AppConst.IntNull.ToString()));
        }

        private void BindC2()
        {
            ddlC2.Items.Clear();
            int c1Sysno = Convert.ToInt32(ddlC1.SelectedItem.Value);

            List<CustomizedCategoryInfo> sl = cm.GetCategoryList(2);
            if (sl != null && sl.Count != 0)
            {
                foreach (CustomizedCategoryInfo item in sl)
                {
                    if (c1Sysno == AppConst.IntNull || item.ParentSysNo == c1Sysno)
                        ddlC2.Items.Add(
                            new ListItem(item.ToString(), item.SysNo.ToString()));
                }
            }
            ddlC2.Items.Insert(0, new ListItem(AppConst.AllSelectString, AppConst.IntNull.ToString()));
        }

        public int C1SysNo
        {
            get
            {
                return Convert.ToInt32(ddlC1.SelectedItem.Value);
            }
        }
        public int C2SysNo
        {
            get
            {
                return Convert.ToInt32(ddlC2.SelectedItem.Value);
            }
            set
            {
                ddlC2.SelectedIndex = ddlC2.Items.IndexOf(ddlC2.Items.FindByValue(value.ToString()));
            }
        }

        protected void ddlC1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindC2();
        }
    }
}